<template>
    <el-dialog v-model="openBatchHandleBoxShow" title="批量事件处理" :close-on-click-modal="false"
        :close-on-press-escape="false">
        <el-form ref="refHandleForm" :model="openBatchHandleForm" label-width="auto" :rules="eventRules">
            <el-form-item label="处理结果" prop="handle_result">
                <el-radio-group v-model="openBatchHandleForm.handle_result">
                    <el-radio v-for="(item, index) in handleResult" :label="item.name" :key="index" border>{{ item.name
                    }}</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="处理备注">
                <el-input type="textarea" v-model="openBatchHandleForm.handle_remark" rows="8" style="width:80%;"
                    placeholder="处理备注" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div style="flex: auto">
                <el-button @click="closeBatchHandleBox">取消</el-button>
                <el-button type="primary" @click="batchOnSubmit">确认</el-button>
            </div>
        </template>
    </el-dialog>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'
import { batchHandleEvent } from '@/api/event.services'
const emits = defineEmits(['success'])
const openBatchHandleBoxShow = ref(false)
const openBatchHandleForm = ref({})
const eventRules = reactive({
    handle_result: [{ required: true, message: '请选择处理结果', trigger: 'change' }]
})
const handleResult = ref([])
const closeBatchHandleBox = () => {
    openBatchHandleBoxShow.value = false
    openBatchHandleForm.value = {}
}
const event_ids = ref([])
const refHandleForm = ref(null)
const batchOnSubmit = async () => {
    const valid = refHandleForm.value.validate()
    if (!valid) return
    const postData = {
        event_id: event_ids.value.map(item => item.event_id),
        ...openBatchHandleForm.value
    }
    const result = await batchHandleEvent(postData)
    if (result.code == 1) {
        ElMessage.success('处理成功')
        closeBatchHandleBox()
        emits('success')
    }
}
const open = (ids, data) => {
    event_ids.value = ids
    handleResult.value = data
    openBatchHandleBoxShow.value = true
    openBatchHandleForm.value = {}

}
defineExpose({
    open
})
</script>